package com.ruoyi.ora.netty.channel.domain;

import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.SimpleChannelInboundHandler;

public abstract class ChannelHandlerBase extends SimpleChannelInboundHandler<byte[]> {

    public ChannelFuture writeAndFlush(Channel channel, byte[] bytes){
        if (channel != null && channel.isActive() && channel.isOpen()) {
            return channel.writeAndFlush(new OutMessage() {
                @Override
                protected byte[] getObject() {
                    return bytes;
                }
            });
        }
        return null;
    }

    public ChannelFuture writeAndFlush(Channel channel){
        return writeAndFlush(channel);
    }

}
